<%@ page import="bidsanity.Customer; bidsanity.Bid; bidsanity.Listing" contentType="text/html;charset=UTF-8" %>
<html>
<head>
    <meta name="layout" content="main"/>
    <title>- Customer Manager</title>
</head>

<body>
<h1>Customer Manager</h1>

<g:if test="${flash.message}">
    <div class="message">${flash.message}</div>
</g:if>

<table class="data_table">
    <tr>
        <th>Email</th>
        <g:if test="${session.user && Customer.findByEmailAddress(session.user).isAdmin}">
            <th>Password</th>
        </g:if>
        <th>Listing Count</th>
        <th>Bid Count</th>
    </tr>
    <g:each in="${customers}" status="i" var="customer">
        <tr class="${(i % 2) == 0 ? 'even' : 'odd'}">
            <td><g:link action="show" id="${customer.id}">${customer.emailAddress?.encodeAsHTML()}</g:link></td>
            <g:if test="${session.user && Customer.findByEmailAddress(session.user).isAdmin}">
                <td>${customer.password?.encodeAsHTML()}</td>
            </g:if>
            <td>${Listing.findAllBySeller(customer).size()}</td>
            <td>${Bid.findAllByBidder(customer).size()}</td>
        </tr>
    </g:each>
</table>

<p>Total Number of Customers: ${customerInstanceTotal}</p>
</body>
</html>